import Axios from 'axios';
import {isBrowser} from "../ssr";

const baseUrl = `${import.meta.env.VITE_APP_SERVER_ENDPOINT}/api/`;
const authKey = `${import.meta.env.VITE_APP_AUTH_KEY}`;

Axios.interceptors.request.use(
  (config) => {
    const isExternal = !!config?.url?.startsWith('http');
    const token = isBrowser ? localStorage.getItem(authKey || "authKey") : null;
    if (token && !isExternal) {
      config.headers['Authorization'] = `Bearer ${token}`;
    }
    config.baseURL = baseUrl;
    debugger
    return config;
  },
  (error) => Promise.reject(error)
);
